<template>
    <view>
        <view class="weui-cell bottom headtitle">
            <view class="weui-cell__hd hdwidth">桌号分类</view>
            <view class="weui-cell__bd">编号</view>
            <view class="weui-cell__bd bdwidth">状态</view>
            <view class="weui-cell__ft">
                <view style="margin-left: 40rpx">操作</view>
            </view>
        </view>
        <view class="weui-cells weui-cells_after-title">
            <form @reset="formReset" @submit="formSubmit" v-for="(item, index) in order_list" :key="item.id">
                <view class="weui-cell bottom">
                    <view class="weui-cell__hd hdwidth">{{ item.num }}</view>
                    <view class="weui-cell__bd">{{ item.code }}</view>
                    <view class="weui-cell__bd bdwidth" :style="'color:' + color" v-if="item.state == '1'">排队中前面还有{{ item.pdrs }}人</view>
                    <view class="weui-cell__bd bdwidth" v-if="item.state == '2'">已叫号</view>
                    <view class="weui-cell__bd bdwidth" v-if="item.state == '3'">已作废</view>
                    <view class="weui-cell__ft">
                        <image @tap="sc" :data-id="item.id" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/delete.png"></image>
                    </view>
                </view>
            </form>
        </view>
        <view class="jzz" v-if="!mygd">
            <image class="Rotation" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"></image>
            <view>加载中...</view>
        </view>
        <view class="jzwb" v-if="mygd">
            <view class="hx"></view>
            <view class="wz">加载完毕</view>
            <view class="hx"></view>
        </view>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
var util = require('../../../utils/util.js');
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            selectedindex: 0,

            topnav: [
                {
                    img: '../static/icon/dzt.png',
                    img1: '../static/icon/wdzt.png',
                    name: '全部'
                },
                {
                    img: '../static/icon/djd.png',
                    img1: '../static/icon/wdjd.png',
                    name: '待支付'
                },
                {
                    img: '../static/icon/ywc.png',
                    img1: '../static/icon/wywc.png',
                    name: '已完成'
                },
                {
                    img: '../static/icon/sh.png',
                    img1: '../static/icon/wsh.png',
                    name: '已关闭'
                }
            ],

            open: false,
            pagenum: 1,
            order_list: [],
            storelist: [],
            mygd: false,
            jzgd: true,
            selecttype: false,
            typename: '选择类型',
            selectdate: false,
            datetype: ['全部', '今天', '昨天', '近七天', '本月'],
            start: '',
            timestart: '',
            timeend: '',
            start_time: '',
            end_time: '',
            color: ''
        };
    },
    onLoad: function (t) {
        var e = uni.getStorageSync('sjdsjid');
        console.log(e, t);
        var a = util.formatTime(new Date()).substring(0, 10).replace(/\//g, '-');
        console.log(a.toString());
        this.setData({
            typename: t.typename,
            start: a,
            timestart: a,
            timeend: a
        });
        uni.setNavigationBarTitle({
            title: t.typename + '领取记录'
        });
        this.reLoad();
        app.globalData.setNavigationBarColor(this);
    },
    onPullDownRefresh: function () {},
    onReachBottom: function () {
        console.log('上拉加载', this.pagenum);
        if (!this.mygd && this.jzgd) {
            this.setData({
                jzgd: false
            });
            this.reLoad();
        }
    },
    methods: {
        reLoad: function () {
            var that = this;
            var t = uni.getStorageSync('sjdsjid');
            var e = this.pagenum;
            var i = this.typename;
            console.log(t, e, i);
            app.globalData.util.request({
                url: 'entry/wxapp/lqNumberList',
                cachetime: '0',
                data: {
                    typename: i,
                    store_id: t,
                    page: e,
                    pagesize: 10
                },
                success: function (t) {
                    console.log('分页返回的列表数据', t.data);
                    if (t.data.length < 10) {
                        that.setData({
                            mygd: true,
                            jzgd: true
                        });
                    } else {
                        that.setData({
                            jzgd: true,
                            pagenum: that.pagenum + 1
                        });
                    }
                    var e = that.storelist;
                    e = (function (t) {
                        for (var e = [], a = 0; a < t.length; a++) {
                            if (-1 == e.indexOf(t[a])) {
                                e.push(t[a]);
                            }
                        }
                        return e;
                    })((e = e.concat(t.data)));
                    that.setData({
                        order_list: e,
                        storelist: e
                    });
                    console.log(e);
                }
            });
        },

        sc: function (t) {
            var that = this;
            var a = t.currentTarget.dataset.id;
            console.log(a);
            uni.showModal({
                title: '提示',
                content: '确认删除此记录吗？',
                success: function (t) {
                    if (t.confirm) {
                        console.log('用户点击确定');
                        app.globalData.util.request({
                            url: 'entry/wxapp/DelNumberCode',
                            cachetime: '0',
                            data: {
                                id: a
                            },
                            success: function (t) {
                                console.log(t);
                                if (1 == t.data) {
                                    uni.showToast({
                                        title: '操作成功',
                                        duration: 1000
                                    });
                                    setTimeout(function () {
                                        that.setData({
                                            pagenum: 1,
                                            order_list: [],
                                            storelist: [],
                                            mygd: false,
                                            jzgd: true
                                        });
                                        that.reLoad();
                                    }, 1000);
                                }
                            }
                        });
                    } else {
                        if (t.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                }
            });
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        },

        formSubmit() {
            console.log('占位：函数 formSubmit 未声明');
        }
    }
};
</script>
<style>
@import './pdxq.css';
</style>
